package com.yilin.platform.entity.capital;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yilin.platform.base_core.application.BaseEntity;
import com.yilin.platform.base_core.application.FlowField;
import com.yilin.platform.base_core.commons.utils.FieldUtil;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.lang.reflect.Field;
import java.util.Date;

@Entity
@Table(name = "capital_trade_flow")
@TableName(value = "capital_trade_flow")
public class TradeFlow extends BaseEntity {
    public enum PayType {
        weixin(0, "微信支付"),
        alipay(1, "支付宝"),
        cmbcPay(2, "民生银行"),
        pabPay(3, "平安银行");
        @EnumValue
        public Integer index;
        public String name;

        PayType(Integer index, String name) {
            this.index = index;
            this.name = name;
        }
    }

    public enum PaymentType {
        expenditure(0, "支出"),
        income(1, "收入"),
        frozen(2, "冻结"),
        thaw(3, "解冻");
        @EnumValue
        public Integer index;
        public String name;

        PaymentType(Integer index, String name) {
            this.index = index;
            this.name = name;
        }
    }

    public enum Upper {
        yes(0, "上送对账"),
        no(1, "不上送对账");
        @EnumValue
        public Integer index;
        public String name;

        Upper(Integer index, String name) {
            this.index = index;
            this.name = name;
        }
    }

    // 公共：设置流水字段
    public <T extends BaseEntity> void putFieldByRecord(T tradeRecord, String fieldName) {
        putFieldByRecord( tradeRecord, fieldName,fieldName);
    }

    // 公共：设置流水字段
    public <T extends BaseEntity> void putFieldByRecord(T tradeRecord, String myFieldName,String tarAnnName) {
        Field tarField = FieldUtil.queryFiledByAnnValue(tradeRecord.getClass(), FlowField.class, ann -> ann.name().equals(tarAnnName));
        Field myField = FieldUtil.getField(this.getClass(), myFieldName);
        if (tarField == null || myField == null) return;
        FieldUtil.objSet(this, myField, FieldUtil.objGet(tradeRecord, tarField));
    }

    // 我的信息
    @Column(name = "holder_organize_id")
    private String holderOrganizeId;//所属人[平台]组织ID
    @Column(name = "holder_name")
    private String holderName;//所属人账户名称
    @Column(name = "holder_bank_acc_no")
    private String holderBankAccNo;//所属人 资金结算户账号/卡号/微信ID/支付宝ID 等
    //对方信息
    @Column(name = "target_organize_id")
    private String targetOrganizeId;//对方[平台]组织ID
    @Column(name = "target_name")
    private String targetName;//对方账户名称
    @Column(name = "target_bank_acc_no")
    private String targetBankAccNo;//对方 资金结算户账号/卡号/微信ID/支付宝ID 等
    //流水信息
    @Column(name = "trans_name")
    private String transName;//交易名称【银行编码等】
    @Column(name = "trade_no")
    private String tradeNo;//本地流水号
    @Column(name = "bank_flow_no")
    private String bankFlowNo;//第三方流水号
    @Column(name = "pay_type")
    private PayType payType;//支付方式
    @Column(name = "money")
    private Double money;//交易金额
    @Column(name = "payment_type")
    private PaymentType paymentType;//收支类型
    @Column(name = "upper")
    private Upper upper;//收支类型
    @Column(name = "trades_date")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date tradesDate;//交易日期

    public String getHolderOrganizeId() {
        return holderOrganizeId;
    }

    public void setHolderOrganizeId(String holderOrganizeId) {
        this.holderOrganizeId = holderOrganizeId;
    }

    public String getHolderName() {
        return holderName;
    }

    public void setHolderName(String holderName) {
        this.holderName = holderName;
    }

    public String getHolderBankAccNo() {
        return holderBankAccNo;
    }

    public void setHolderBankAccNo(String holderBankAccNo) {
        this.holderBankAccNo = holderBankAccNo;
    }

    public String getTargetOrganizeId() {
        return targetOrganizeId;
    }

    public void setTargetOrganizeId(String targetOrganizeId) {
        this.targetOrganizeId = targetOrganizeId;
    }

    public String getTargetName() {
        return targetName;
    }

    public void setTargetName(String targetName) {
        this.targetName = targetName;
    }

    public String getTargetBankAccNo() {
        return targetBankAccNo;
    }

    public void setTargetBankAccNo(String targetBankAccNo) {
        this.targetBankAccNo = targetBankAccNo;
    }

    public String getTransName() {
        return transName;
    }

    public void setTransName(String transName) {
        this.transName = transName;
    }

    public String getTradeNo() {
        return tradeNo;
    }

    public void setTradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
    }

    public String getBankFlowNo() {
        return bankFlowNo;
    }

    public void setBankFlowNo(String bankFlowNo) {
        this.bankFlowNo = bankFlowNo;
    }

    public PayType getPayType() {
        return payType;
    }

    public void setPayType(PayType payType) {
        this.payType = payType;
    }

    public Double getMoney() {
        return money;
    }

    public void setMoney(Double money) {
        this.money = money;
    }

    public PaymentType getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(PaymentType paymentType) {
        this.paymentType = paymentType;
    }

    public Upper getUpper() {
        return upper;
    }

    public void setUpper(Upper upper) {
        this.upper = upper;
    }

    public Date getTradesDate() {
        return tradesDate;
    }

    public void setTradesDate(Date tradesDate) {
        this.tradesDate = tradesDate;
    }
}
